package pers.amos.eshop.advance.data.sync.mq;

import cn.hutool.json.JSONObject;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author amos wong
 * @create 2020-12-16 8:57 上午
 */
@Component
public class RabbitMqSender {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void send(String topic, String message) {
        amqpTemplate.convertAndSend(topic, message);
    }

    public String buildSendMessage(String dimType, Long id) {
        JSONObject jsonObject = new JSONObject();
        // 聚合分类，只有四种：product、product_intro、brand、category
        jsonObject.set("dim_type", dimType);
        jsonObject.set("id", id);
        return jsonObject.toString();
    }
}
